package com.ss.test10;

import java.util.Comparator;
import java.util.TreeSet;

/**
 * @Auther: 520ljs
 * @Date: 2022/3/17 - 03 - 17 - 20:37
 */
public class Test04 {
    //这是一个main方法，是程序的入口
    public static void main(String[] args) {
        //创建一个TreeSet:
        //利用外部比较器，必须自己指定：
        //1:
        /*Comparator<Student> com = new BiJiao();*/
        //2:
        /*Comparator<Student> com = new Comparator<Student>() {
            @Override
            public int compare(Student o1, Student o2) {
                return o1.getName().compareTo(o2.getName());
            }
        };*/
        /*TreeSet<Student> ts = new TreeSet<>(com);*///一旦指定外部比较器，那么就会按照外部比较器来比较
        //3:
        TreeSet<Student> ts = new TreeSet<>(new Comparator<Student>() {
            @Override
            public int compare(Student o1, Student o2) {
                return o1.getName().compareTo(o2.getName());
            }
        });//一旦指定外部比较器，那么就会按照外部比较器来比较
        ts.add(new Student(10,"elili"));
        ts.add(new Student(8,"alili"));
        ts.add(new Student(4,"blili"));
        ts.add(new Student(9,"clili"));
        ts.add(new Student(10,"dlili"));
        ts.add(new Student(1,"elili"));
        ts.add(new Student(13,"flili"));
        System.out.println(ts.size());
        System.out.println(ts);
    }
}
